/* eslint-disable */
import legacyPlugin from "@vitejs/plugin-legacy";
import { defineConfig } from "vite";
import * as path from "path";
import { createVuePlugin } from "vite-plugin-vue2";
import resolveExtensionVue from "vite-plugin-resolve-extension-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
const { injectHtml } = require("vite-plugin-html");
const resolveExternalsPlugin = require("vite-plugin-resolve-externals");

const rollupPluginCommonjs = require("rollup-plugin-commonjs");
const rollupPluginNodeResolve = require("rollup-plugin-node-resolve");
const rollupPluginRequireContext = require("rollup-plugin-require-context");
import commonjs from "@rollup/plugin-commonjs";

// @see https://cn.vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  let rollupOptions = {};

  let optimizeDeps = {};

  let alias = {
    "@": path.resolve(__dirname, "./src"),
    "~": "",
    vue$: "vue/dist/vue.runtime.esm.js"
  };

  let proxy = {};

  let define = {
    "process.env.NODE_ENV": '"development"'
  };

  let esbuild = {};
  // ".vue",
  return {
    base: "./", // index.html文件所在位置
    root: "", // js导入的资源路径，src
    resolve: {
      alias,
      extensions: [".vue", ".mjs", , ".js", ".ts", ".jsx", ".tsx", ".json"]
    },
    define: define,
    server: {
      // 代理
      proxy,
      port: 7777
    },
    build: {
      target: "es2015",
      minify: "terser", // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
      manifest: false, // 是否产出maifest.json
      sourcemap: false, // 是否产出soucemap.json
      outDir: "build", // 产出目录
      rollupOptions
    },
    esbuild,
    optimizeDeps,
    plugins: [
      legacyPlugin({
        targets: [
          "Android > 39",
          "Chrome >= 60",
          "Safari >= 10.1",
          "iOS >= 10.3",
          "Firefox >= 54",
          "Edge >= 15"
        ]
      }),
      createVuePlugin(),
      resolveExtensionVue(),
      vueJsx(),
      resolveExternalsPlugin({
        vue: "Vue"
      }),
      rollupPluginNodeResolve(),
      rollupPluginCommonjs(),
      rollupPluginRequireContext()
    ],
    css: {
      preprocessorOptions: {
        less: {
          // 支持内联 JavaScript
          javascriptEnabled: true
        }
      }
    }
  };
});
